package com.css.fxfzypg.modules.auxiliaryDecisionManage.paramSetting.controller;

import com.alibaba.fastjson.JSONObject;
import com.css.fxfzypg.base.response.RestResponse;
import com.css.fxfzypg.logInfo.SysLog;
import com.css.fxfzypg.modules.actionTrack.entity.ActionTrackEntity;
import com.css.fxfzypg.modules.auxiliaryDecisionManage.paramSetting.entity.ParamSetting;
import com.css.fxfzypg.modules.auxiliaryDecisionManage.paramSetting.entity.ParamSettingVO;
import com.css.fxfzypg.modules.auxiliaryDecisionManage.paramSetting.service.ParamSettingService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author: zhangSongRui
 * @CreateTime: 2023/03/22
 * @Description: 参数设置
 */
@RestController
@RequestMapping("/paramSetting")
@Slf4j
public class ParamSettingController {
    @Resource
    private ParamSettingService paramSettingService;

    /***
     * 轨迹保存
     * @param paramSetting
     * @return
     */
    @SysLog("保存参数")
    @PostMapping("/save")
    public RestResponse save(@RequestBody ParamSetting paramSetting){
        RestResponse restResponse=null;
        JSONObject jsonObject=new JSONObject();
        try {
            paramSettingService.save(paramSetting);
            jsonObject.put("message","保存成功");
            restResponse= RestResponse.succeed(jsonObject);
        }catch (Exception e){
            String errormessage = e.getMessage();
            if(StringUtils.isBlank(errormessage)) {
                errormessage = "保存失败";
            }
            log.error(errormessage,e);
            restResponse=RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /**
     * 获取参数
     * @return ParamSetting
     */
    @SysLog("获取参数")
    @GetMapping("/getParamSetting")
    public RestResponse getParamSetting() {
        RestResponse restResponse = null;
        try {
            ParamSettingVO paramSetting=paramSettingService.getParamSetting();
            restResponse = RestResponse.succeed(paramSetting);
        } catch (Exception e) {
            String errormessage = "查询失败";
            log.error(errormessage, e);
            restResponse = RestResponse.fail(errormessage);
        }
        return restResponse;
    }
}
